#include <iostream>
#include <vector>
using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

TreeNode* makeTree(vector<int>& pre, vector<int>& post, int p1, int p2, int p3, int p4){
    if(p1 > p2 || p3 > p4) return nullptr;
    if(p1 == p2 || p3 == p4){
        TreeNode* n = new TreeNode(pre[p1]);
        return n;
    }
    TreeNode* root = new TreeNode(pre[p1]);
    int pos;
    for(int i=p3;i<=p4;i++){
        if(post[i] == pre[p1+1]){
            pos = i;
            break;
        }
    }
    root->left = makeTree(pre, post, p1+1,p1+1+pos-p3, p3, pos);
    root->right = makeTree(pre, post, p1+1+pos-p3+1, p2, pos+1, p4);
    return root; 
}

TreeNode* constructFromPrePost(vector<int>& preorder, vector<int>& postorder) {
    return makeTree(preorder, postorder, 0, preorder.size()-1, 0, postorder.size()-1);
}

int main(){
    cout << "hello world\n";
    return 0;
}